select
  accSub.accountSubjectId,
  accSub.subjectType,
  accSub.fullName,
  accSub.direction,
  subBal.balanceMoney         
 from
  AccountSubjectBoImpl accSub         
 left join
  accSub.subjectBalanceList subBal       
 where
  subBal.subjectBalanceId     =(
   select
    max(subBal2.subjectBalanceId)                    
   from
    SubjectBalanceBoImpl subBal2                    
   where
    subBal2.accountSubject=accSub.accountSubjectId                         
    and subBal2.registerTime<=?
     )
and (accSub.subjectType=0 
  or accSub.subjectType=1 
  or accSub.subjectType=2)
  and accSub.childrenSize <= 0 
order by accSub.subjectCode